<?php
/**
 * Created by PhpStorm.
 * User: t
 * Date: 2024/3/14
 * Time: 15:58
 */



namespace app\http\middleware;

use app\admin\service\AdminUserService;
use app\common\model\Menu;
use app\Request;


class AuthVerify
{
    protected $auth_role = [
        '/auth/user',
    ];
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle(Request $request, \Closure $next)
    {
        $adminUserService  = new AdminUserService();

        $adminUser = $adminUserService->selectAdminUserRole($request->admin_id);
        if ($adminUser['code'] == 0){
           return error($adminUser['msg']);
        }
        $roleIds = array_column($adminUser['data'],'id');
        $url = $request->rule()->getName();
        $menu = $adminUserService->getRoleMenu($roleIds,$url);
         if($menu['code'] == 0){
            return error($menu['msg']);
        }
        return $next($request);
    }


}